package com.woniuxy.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.woniuxy.entity.dto.AddOrderListDTO;
import com.woniuxy.service.TakeOutGoodsService;
import com.woniuxy.util.ResponseData;
import com.woniuxy.util.ResponseEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @BelongsProject: pigTrotterStore
 * @BelongsPackage: com.woniuxy.controller
 * @Author: Quan
 * @Date: 2025/3/21 14:48
 */
@RestController
@RequestMapping("/takeOutGoods")
public class TakeOutGoodsController {
	@Autowired
	private TakeOutGoodsService takeOutGoodsService;

	/**
	 * @Description: 查询所有的商品名
	 * @Param: []
	 * @return: com.woniuxy.util.ResponseData<?>
	 * @Author: Quan
	 * @Date: 2025/3/21
	 */
	@GetMapping("/queryAll")
	public ResponseData<?> queryAll() {
		return takeOutGoodsService.queryAll();
	}

	@PostMapping("/addTakeOutOrder")
	public ResponseData<?> addTakeOutOrder(@RequestBody List<AddOrderListDTO> addOrderMsgList) {
		if (!CollectionUtil.isEmpty(addOrderMsgList)) {
			try {
				return takeOutGoodsService.addTakeOutOrder(addOrderMsgList);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		} else {
			return ResponseData.fail(ResponseEnum.DO_NOT_PLACE_ORDER);
		}
	}

	@GetMapping("/payMoney/{orderNum}")
	public ResponseData<?> payMoney(@PathVariable("orderNum") String orderNum) {
		return takeOutGoodsService.payMoney(orderNum);
	}

	@GetMapping("/queryFoodInfo/{foodName}")
	public ResponseData<?> queryFoodInfo(@PathVariable("foodName") String foodName) {
		return takeOutGoodsService.queryFoodInfo(foodName);
	}
}
